package com.zq.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2020/12/31  10:55
 * 修改日期：
 * 描    述：
 * 修订历史：
 * ================================================
 */
@EnableEurekaClient // 服务启动自动注册到eureka
@EnableDiscoveryClient // 服务发现
@SpringBootApplication
@EnableHystrix // 开启熔断的支持
@MapperScan("com.zq.springcloud.dao")
public class HystrixEmpProvider {
    public static void main(String[] args) {
        SpringApplication.run(HystrixEmpProvider.class, args);
    }

    /**
     * 增加一个servlet
     * 配合Dashboard流监控使用
     * 使用步骤：启动eureka集群、dashboard监控、hystrix提供者9001：http://localhost:9001/hystrix/
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> test() {
        ServletRegistrationBean<HystrixMetricsStreamServlet> registration = new
                ServletRegistrationBean<HystrixMetricsStreamServlet>(new HystrixMetricsStreamServlet());
        registration.addUrlMappings("/actuator/hystrix.stream");
        return registration;
    }
}
